home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
ms_dos
/
txf
/
src
/
txfetc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
5KB
|
234 lines
/***************
*
* g:\exe\txf\src\txfetc.c
*/
#include "txf.h"
int hex(char *str)
{
int i, j, val = 0;
for (j = 0; j < 2; j++) {
i = (int)(*(str + j));
if ((i < 0x30) || (i > 0x66)) i = 0;
if (i > 0x60) i -= 0x57;
if (i > 0x46) i = 0;
if (i > 0x40) i -= 0x37;
if (i > 0x39) i = 0;
if (i > 0x2f) i -= 0x30;
val += (i * ((j == 0) ? 16 : 1));
}
return (val);
}
char *ftrans(char *form)
{
int i = 0, j = 0, k = 0;
int len = strlen(form);
int chrattr = CT_ANK, lowk, highk;
char *original, *attr, *tmp, *str;
if (form == NULL) {
errexit("find NULL pointer(ftrans)");
}
attr = malloc(len + 1);
original = form;
tmp = malloc(3000);
if (tmp == NULL) {
errexit("out of memory at ftrans()");
}
for (i = 0; *(original + i) != NUL; i++) {
chrattr = chkctype(*(original + i), chrattr);
*(attr + i) = chrattr;
}
for (i = 0; i < len; i++) {
if ((*(original + i) == 0x5c) && (*(attr + i) == CT_ANK)) {
i++;
switch (*(original + i)) {
case 0x5c:
*(tmp + j) = 0x5c;
break;
case '-':
*(tmp + j) = '-';
break;
case '#':
*(tmp + j) = '#';
break;
case '_':
*(tmp + j) = ' ';
break;
case 0x81:
if (*(original + i + 1) == 0x51) {
i++;
*(tmp+j) = 0x81;
j++;
*(tmp+j) = 0x40;
}
break;
case 'e':
*(tmp + j) = '=';
break;
case 'd':
*(tmp + j) = 0x22;
break;
case 'n':
*(tmp + j) = 0x0d;
j++;
*(tmp + j) = 0x0a;
break;
case 't':
*(tmp + j) = TAB;
break;
case 's':
*(tmp + j) = ';';
break;
case 'r':
*(tmp + j) = '>';
break;
case 'l':
*(tmp + j) = '<';
break;
case 'v':
*(tmp + j) = '|';
break;
case 'x':
*(tmp + j) = hex(original + i + 1);
i += 2;
break;
case 'X':
*(tmp + j) = hex(original + i + 1);
j++;
*(tmp + j) = hex(original + i + 3);
i += 4;
break;
default:
*(tmp + j) = *(original + i);
}
}
else if ((*(original + i) == '-') && (*(attr + i) == CT_ANK)) {
if ((*(attr + i - 1) == CT_ANK) && (*(attr + i + 1) == CT_ANK)) {
for (k = 1; (*(original+i-1) + k) <= *(original+i+1); k++) {
*(tmp + (j++)) = *(original + i - 1) + k;
}
i++;
j--;
}
else if ((*(attr+i-1) == CT_KJ2) && (*(attr+i+1) == CT_KJ1)) {
lowk = (*(original + i - 2) << 8) | *(original + i - 1);
highk = (*(original + i + 1) << 8) | *(original + i + 2);
for (k = (lowk + 1); k <= highk; k++) {
*(tmp + (j++)) = k >> 8;
*(tmp + (j++)) = k & 0xff;
}
i += 2;
j--;
}
}
else {
(*(tmp + j)) = (*(original + i));
}
j++;
}
*(tmp + j) = NUL;
str = malloc(strlen(tmp) + 1);
strcpy(str, tmp);
free(attr);
free(tmp);
return (str);
}
int quotechk(int chr1, int chr2)
{
if (iskanji(chr1)) {
if (jstrchr(kq, (chr2 | (chr1 << 8))) != NULL) return (1);
}
else {
if (jstrchr(kq, (chr1 & 0x0ff)) != NULL) return (1);
}
return (0);
}
char *strspc(char *ptr, char find)
{
while (*ptr != find) {
if (*ptr == NUL) {
return (ptr);
}
*ptr = NUL;
ptr++;
}
return (ptr);
}
char *ktrans(char *str)
{
char *buf;
buf = ftrans(str);
return (buf);
}
void init_allswitch()
{
int i;
inputfile[0] = NUL;
outputfile[0] = NUL;
for (i = 0; i < PARA_MAX; i++) {
para[i] = NULL;
}
for (i = 0; i < 2; i++) {
tfile[i][0] = NUL;
}
for (i = 0; i < 16; i++) {
exold[i] = NULL;
exnew[i] = NULL;
}
*bakfile = NUL; /* -rb */
tabsize = 8; /* -t */
tabx = 0; /* -x tab展開 */
maxc = 76; /* -l */
cent = 0; /* -c */
left = -1; /* -ml */
right = -1; /* -mr */
retflg = 0; /* -r */
quoteflg = 0; /* -q 引用文 */
base = -1; /* -b */
tfile[0][0] = NUL; /* -d */
tfile[1][0] = NUL; /* -d */
exflg = 0; /* -e */
format = 1; /* -n,-f */
viewmode = 0; /* -v */
sep = 0x22; /* -s */
removeeofflg = 0;
removebakfile = 0;
useoldex = 0;
}
void gettmpfile()
{
if (getenv("TMP") != NULL) {
strncpy(tfile[0], getenv("TMP"), 64);
if (viewmode > 3) {
fprintf(stderr, "TMP 0:%s\n", tfile[0]);
}
}
else {
strncpy(tfile[0], basedir, 80);
if (strchr(tfile[0], 0x5c) != NULL) {
*(strrchr(tfile[0], 0x5c)) = NUL;
}
else if (strrchr(tfile[0], ':') != NULL) {
*(strrchr(tfile[0], ':') + 1) = NUL;
}
else{
tfile[0][0] = NUL;
}
if (viewmode > 3) {
fprintf(stderr, "TMP 0:%s\n", tfile[0]);
}
}
}